package org.dromara.patrol.controller;


import lombok.RequiredArgsConstructor;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.patrol.domain.bo.PatrolTaskBo;
import org.dromara.patrol.domain.bo.PatrolTaskQuery;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.patrol.domain.vo.PatrolSubtaskCommonVo;
import org.dromara.patrol.service.IPatrolSubtaskCommonService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

import java.util.List;

/**
 * 巡店管理-普通巡店子任务
 * 前端访问路由地址为:/patrol/task
 *
 * @author Chan
 * @date 2024-03-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/patrol/task")
public class PatrolSubtaskCommonController extends BaseController {

    private final IPatrolSubtaskCommonService patrolSubtaskCommonService;

    /**
     * 查询巡店管理-普通巡店子任务列表
     */
//    @SaCheckPermission("patrol:subtaskCommon:list")
    @PostMapping("/list")
    public TableDataInfo<PatrolSubtaskCommonVo> list(@RequestBody PatrolTaskQuery patrolTaskQuery) {
        return patrolSubtaskCommonService.queryPageList(patrolTaskQuery);
    }

    /**
     * 获取巡店管理-普通巡店子任务详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("patrol:subtaskCommon:query")
    @GetMapping("/{id}")
    public R<PatrolSubtaskCommonVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(patrolSubtaskCommonService.queryById(id));
    }

    /**
     * 修改巡店管理-普通巡店子任务
     */
    @SaCheckPermission("patrol:subtaskCommon:edit")
    @Log(title = "巡店管理-普通巡店子任务", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit/{id}")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PatrolTaskBo bo,
                        @NotNull(message = "子任务主键不能为空") @PathVariable Long id) {
        return toAjax(patrolSubtaskCommonService.updateByBo(bo, id));
    }

    /**
     * 删除巡店管理-普通巡店子任务（MainTask = 主任务）
     *
     * @param id 主键串
     */
    @SaCheckPermission("patrol:subtaskCommon:remove")
    @Log(title = "巡店管理-普通巡店子任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@NotNull(message = "主键不能为空")
                          @PathVariable Long id) {
        return toAjax(patrolSubtaskCommonService.deleteWithId(id));
    }
}
